package com.wenjh.jdmzt.service.model;

import com.wenjh.jdmzt.android.synctask.LoadImageUtil.ImageCallback;
import com.wenjh.jdmzt.service.dao.ITable;
import com.wenjh.jdmzt.util.StringUtils;

public class Image implements ImageLoadable {
	private String urlString;
	private String imageId;
	private int width, height;
	private int supportCount;
	private int unsupportCount;
	private String id;
	private int type;
	
	public Image(String url) {
		setUrlString(url);
	}
	
	public Image() {
	}
	
	public String getUrlString() {
		return urlString;
	}
	
	public void setUrlString(String urlString) {
		this.urlString = urlString;
		imageId = StringUtils.md5(urlString);
	}
	
	public String getImageId() {
		if(imageId == null) {
			return "";
		} else {
			return imageId;
		}
	}
	
	public void setType(int type) {
		this.type = type;
	}
	
	public int getType() {
		return type;
	}
	
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	public boolean isGif() {
		return urlString.endsWith(".gif");
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	@Override
	public String getLoadImageId() {
		return getImageId();
	}

	boolean imageloading = false;
	@Override
	public boolean isImageLoading() {
		return imageloading;
	}

	@Override
	public void setImageLoading(boolean loading) {
		imageloading = loading;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((imageId == null) ? 0 : imageId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Image other = (Image) obj;
		if (imageId == null) {
			if (other.imageId != null)
				return false;
		} else if (!imageId.equals(other.imageId))
			return false;
		return true;
	}

	ImageCallback callback = null;
	public ImageCallback getImageCallback() {
		return callback;
	}
	public void setImageCallback(ImageCallback callback) {
		this.callback = callback;
	}
	
	
	public int getSupportCount() {
		return supportCount;
	}
	
	public void setSupportCount(int supportCount) {
		this.supportCount = supportCount;
	}
	
	public int getUnsupportCount() {
		return unsupportCount;
	}
	
	public void setUnsupportCount(int unsupportCount) {
		this.unsupportCount = unsupportCount;
	}
	
	public interface Table extends ITable {
		String TableName = "images";
		String F_ImageId = DBFILED_TMP+"1";
		String F_Url = DBFILED_TMP+"2";
		String F_Support = DBFILED_TMP+"3";
		String F_Unsupport = DBFILED_TMP+"4";
		String F_Type = DBFILED_TMP+"5";
	}
}
